{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "84c6ff9c",
   "metadata": {},
   "source": [
    "Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n",
    "SPDX-License-Identifier: Apache-2.0\n",
    "\n",
    "# People Analytics using Neptune ML - Predicting Attrition and Career Progression\n",
    "\n",
    "Hiring and retaining good personnel is a key characteristic to making an organization sucessful.  One way that organizations approach this problem is through the use of people analytics.  People analytics allow business leaders to make data-driven decisions about personnel-related issues such as recruiting, evaluation, hiring, promotion, and retention, etc.\n",
    "\n",
    "Human resource and personnel data often contains a vast amount of information that shows the connections and relationships between individuals, companies, jobs, etc. such as:\n",
    "\n",
    "* Who works for whom\n",
    "* How has this person's career progressed\n",
    "* What opportunities has this person had\n",
    "\n",
    "This type of information can be efficently and effectively represented in the form of a graph.  Storing and thinking about this data as a series of connections enable us to gain some unique insights.  \n",
    "\n",
    "In this notebook we will answer two specific questions that come up frequently when looking at HR data in terms of hiring and retaining personnel:\n",
    "\n",
    "* Who is most likely to leave?\n",
    "* What job should someone look at next?\n",
    "\n",
    "To demonstrate how you might accomplish this we are going to use a well-known dataset originally from IBM that contains HR attrition data.  This dataset is available from [Kaggle](https://www.kaggle.com/pavansubhasht/ibm-hr-analytics-attrition-dataset) under the [Open Data Commons License]( https://opendatacommons.org/licenses/dbcl/1-0/).\n",
    "\n",
    "To answer these questions, we will be using [Neptune ML](https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning.html) which is a feature of Amazon Neptune that enables users to automate the creation, management, and usage of Graph Neural Network (GNN) machine learning models within Amazon Neptune.  Neptune ML is built using [Amazon SageMaker](https://aws.amazon.com/sagemaker/) and [Deep Graph Library](https://www.dgl.ai/) and provides a simple and easy-to-use mechanism to build/train/maintain these models and then use the predictive capabilities of these models within a Gremlin query to predict elements or property values in the graph.\n",
    "\n",
    "## Setup\n",
    "\n",
    "Before we begin, we need to setup a few things. Most importantly, you will need to provide the path to an Amazon S3 bucket that we can use to store our data in."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "35b40b85",
   "metadata": {},
   "outputs": [],
   "source": [
    "!cp ../../neptune_ml_utils.py ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37e9b0af",
   "metadata": {},
   "outputs": [],
   "source": [
    "import neptune_ml_utils as neptune_ml\n",
    "neptune_ml.check_ml_enabled()\n",
    "\n",
    "s3_bucket_uri=\"s3://<INSERT S3 BUCKET OR PATH>\"\n",
    "# remove trailing slashes\n",
    "s3_bucket_uri = s3_bucket_uri[:-1] if s3_bucket_uri.endswith('/') else s3_bucket_uri"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ecf827ae",
   "metadata": {},
   "source": [
    "## Import and explore data\n",
    "\n",
    "Let's start by loading up the data using the associated CSV file and see what our data looks like. *Note* - This notebook assumes the cluster was empty before this command being run."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2d8dc75c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "df = pd.read_csv('WA_Fn-UseC_-HR-Employee-Attrition.csv')\n",
    "pd.set_option('display.max_columns', None)\n",
    "print(f'Our data file contains {df.shape[0]} columns and {df.shape[1]} rows.')\n",
    "print('Here is what a few of them look like:')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c24a472",
   "metadata": {},
   "source": [
    "As you can see, the data contains 1470 rows and 35 columns.  Let's see how much overlap is in our data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8bb09372",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(f'Number of unique employees: {df[\"EmployeeNumber\"].nunique()}')\n",
    "print(f'Number of unique departments: {df[\"Department\"].nunique()}')\n",
    "print(f'Number of unique fields: {df[\"EducationField\"].nunique()}')"
   ]
  },
  {
   "attachments": {
    "image.png": {
     "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZsAAAEjCAYAAADkAazgAAAgAElEQVR4Ae19CVhVR5r2l9n+mU7b/0x3T3r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   "metadata": {},
   "source": [
    "Now that we have a high-level view of the data in our file, let's import it into Neptune.\n",
    "\n",
    "## Import into Neptune\n",
    "\n",
    "To accomplish our data import into Neptune we are going to use the [Neptune Bulk Loader](https://docs.aws.amazon.com/neptune/latest/userguide/bulk-load.html) with a CSV file format.  \n",
    "\n",
    "Vertices loaded from a CSV are required to be in this format:\n",
    "    \n",
    "    ~id, name:String, age:Int, lang:String, ~label\n",
    "    v1, \"brad\", 29, , person\n",
    "    \n",
    "Edges loaded from a CSV are required to be in this format:\n",
    "\n",
    "    ~id, ~from, ~to, ~label, weight:Double\n",
    "    e1, v1, v2, created, 0.4\n",
    "    \n",
    "Let's convert the employee data from our file into a compatible set of vertices and edges.         \n",
    "\n",
    "* vertices\n",
    "    * Employee\n",
    "        * Age (int)\n",
    "        * Attrition (categorical)\n",
    "        * BusinessTravel (categorical)\n",
    "        * DailyRate (int)\n",
    "        * DistanceFromHome (int, but likely represents a category)\n",
    "        * Education (int, but likely represents a category)\n",
    "        * EmployeeCount (int)\n",
    "        * EmployeeNumber (int)\n",
    "        * EnvironmentSatisfaction (int, but likely represents a category)\n",
    "        * Gender (category)\n",
    "        * HourlyRate (int)\n",
    "        * JobInvolvement (int, but likely represents a category)\n",
    "        * JobLevel (int, but likely represents a category)\n",
    "        * JobSatisfaction  (int, but likely represents a category)\n",
    "        * MaritalStatus (category)\n",
    "        * MonthlyIncome (int)\n",
    "        * MonthlyRate (int)\n",
    "        * NumCompaniesWorked (int)\n",
    "        * Over18 (category)\n",
    "        * OverTime (category)\n",
    "        * PercentSalaryHike (int)\n",
    "        * PerformanceRating  (int, but likely represents a category)\n",
    "        * RelationshipSatisfaction (int, but likely represents a category)\n",
    "        * StandardHours (int)\n",
    "        * StockOptionLevel (int, but likely represents a category)\n",
    "        * TotalWorkingYears (int)\n",
    "        * TrainingTimesLastYear (int)\n",
    "        * WorkLifeBalance (int, but likely represents a category)\n",
    "        * YearsAtCompany (int)\n",
    "        * YearsInCurrentRole (int)\n",
    "        * YearsSinceLastPromotion (int)\n",
    "        * YearsWithCurrManager (int)\n",
    "    * Department\n",
    "        * Department (string)\n",
    "    * EducationField\n",
    "        * EducationField (string)\n",
    "    * JobRole\n",
    "        * JobRole (string)\n",
    "* edges\n",
    "    * Employee-works_in->Department\n",
    "    * Employee-has_education_level->EducationField\n",
    "    * Employee-works_as->JobRole\n",
    "    * JobRole-requires->EducationField\n",
    "    * JobRole-part_of->Department\n",
    "    \n",
    "In our graph, our data model will look like this:\n",
    "\n",
    "![image.png](attachment:image.png)\n",
    "        \n",
    "Using this model, we will try to predict the following:\n",
    "\n",
    "* Attrition (node classification)\n",
    "* Possible job roles (link prediction)\n",
    "\n",
    "Before we can do that, we first need to create the CSV files and then upload them to S3, which is accomplished by running the two cells below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ce38e391",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import boto3\n",
    "import os\n",
    "import uuid\n",
    "from urllib.parse import urlparse\n",
    "\n",
    "# Create the output folder\n",
    "output_folder = 'data-upload'\n",
    "if os.path.exists(output_folder) == False:\n",
    "    os.mkdir(output_folder)\n",
    "\n",
    "# Create the Employee dataframe\n",
    "empVdf = pd.DataFrame(columns=['~id', \n",
    "                               'Age:Int',\n",
    "                                'Attrition:String',\n",
    "                                'BusinessTravel:String',\n",
    "                                'DailyRate:Int',\n",
    "                                'DistanceFromHome:String',\n",
    "                                'Education:String',\n",
    "                                'EmployeeCount:Int',\n",
    "                                'EmployeeNumber:Int',\n",
    "                                'EnvironmentSatisfaction:String',\n",
    "                                'Gender:String',\n",
    "                                'HourlyRate:Int',\n",
    "                                'JobInvolvement:String',\n",
    "                                'JobLevel:String',\n",
    "                                'JobSatisfaction:String',\n",
    "                                'MaritalStatus:String',\n",
    "                                'MonthlyIncome:Int',\n",
    "                                'MonthlyRate:Int',\n",
    "                                'NumCompaniesWorked:Int',\n",
    "                                'Over18:String',\n",
    "                                'OverTime:String',\n",
    "                                'PercentSalaryHike:Int',\n",
    "                                'PerformanceRating:String',\n",
    "                                'RelationshipSatisfaction:String',\n",
    "                                'StandardHours:Int',\n",
    "                                'StockOptionLevel:String',\n",
    "                                'TotalWorkingYears:Int',\n",
    "                                'TrainingTimesLastYear:Int',\n",
    "                                'WorkLifeBalance:String',\n",
    "                                'YearsAtCompany:Int',\n",
    "                                'YearsInCurrentRole:Int',\n",
    "                                'YearsSinceLastPromotion:Int',\n",
    "                                'YearsWithCurrManager:Int',\n",
    "                               '~label'])\n",
    "empVdf['Age:Int'] = df['Age']\n",
    "empVdf['Attrition:String'] = df['Attrition']\n",
    "empVdf['BusinessTravel:String'] = df['BusinessTravel']\n",
    "empVdf['DailyRate:Int'] = df['DailyRate']\n",
    "empVdf['DistanceFromHome:String'] = df['DistanceFromHome']\n",
    "empVdf['Education:String'] = df['Education']\n",
    "empVdf['EmployeeCount:Int'] = df['EmployeeCount']\n",
    "empVdf['EmployeeNumber:Int'] = df['EmployeeNumber']\n",
    "empVdf['EnvironmentSatisfaction:String'] = df['EnvironmentSatisfaction']\n",
    "empVdf['Gender:String'] = df['Gender']\n",
    "empVdf['HourlyRate:Int'] = df['HourlyRate']\n",
    "empVdf['JobInvolvement:String'] = df['JobInvolvement']\n",
    "empVdf['JobLevel:String'] = df['JobLevel']\n",
    "empVdf['JobSatisfaction:String'] = df['JobSatisfaction']\n",
    "empVdf['MaritalStatus:String'] = df['MaritalStatus']\n",
    "empVdf['MonthlyIncome:Int'] = df['MonthlyIncome']\n",
    "empVdf['MonthlyRate:Int'] = df['MonthlyRate']\n",
    "empVdf['NumCompaniesWorked:Int'] = df['NumCompaniesWorked']\n",
    "empVdf['Over18:String'] = df['Over18']\n",
    "empVdf['OverTime:String'] = df['OverTime']\n",
    "empVdf['PercentSalaryHike:Int'] = df['PercentSalaryHike']\n",
    "empVdf['PerformanceRating:String'] = df['PerformanceRating']\n",
    "empVdf['RelationshipSatisfaction:String'] = df['RelationshipSatisfaction']\n",
    "empVdf['StandardHours:Int'] = df['StandardHours']\n",
    "empVdf['StockOptionLevel:String'] = df['StockOptionLevel']\n",
    "empVdf['TotalWorkingYears:Int'] = df['TotalWorkingYears']\n",
    "empVdf['TrainingTimesLastYear:Int'] = df['TrainingTimesLastYear']\n",
    "empVdf['WorkLifeBalance:String'] = df['WorkLifeBalance']\n",
    "empVdf['YearsAtCompany:Int'] = df['YearsAtCompany']\n",
    "empVdf['YearsInCurrentRole:Int'] = df['YearsInCurrentRole']\n",
    "empVdf['YearsSinceLastPromotion:Int'] = df['YearsSinceLastPromotion']\n",
    "empVdf['YearsWithCurrManager:Int'] = df['YearsWithCurrManager']\n",
    "\n",
    "empVdf['~label'] = 'Employee'\n",
    "empVdf['~id'] = np.arange(len(empVdf))\n",
    "empVdf['~id'] = empVdf['~id'].apply(lambda x: f\"emp{x}\")\n",
    "empVdf.to_csv(os.path.join(output_folder, 'vertex_emp.csv'), index=False)\n",
    "emp_map = pd.Series(empVdf['~id'].values,index=empVdf['EmployeeNumber:Int']).to_dict()\n",
    "\n",
    "# Create the Department dataframe\n",
    "deptVdf = pd.DataFrame(columns=['~id', \n",
    "                               'Name:String',                                \n",
    "                               '~label'])\n",
    "deptVdf['Name:String'] = df['Department']\n",
    "\n",
    "deptVdf['~label'] = 'Department'\n",
    "deptVdf = deptVdf.drop_duplicates(subset=['Name:String'])\n",
    "deptVdf['~id'] = np.arange(len(deptVdf))\n",
    "deptVdf['~id'] = deptVdf['~id'].apply(lambda x: f\"dept{x}\")\n",
    "deptVdf.to_csv(os.path.join(output_folder, 'vertex_dept.csv'), index=False)\n",
    "dept_map = pd.Series(deptVdf['~id'].values,index=deptVdf['Name:String']).to_dict()\n",
    "\n",
    "# Create the JobRole dataframe\n",
    "roleVdf = pd.DataFrame(columns=['~id', \n",
    "                               'Name:String',                                \n",
    "                               '~label'])\n",
    "roleVdf['Name:String'] = df['JobRole']\n",
    "\n",
    "roleVdf['~label'] = 'JobRole'\n",
    "roleVdf = roleVdf.drop_duplicates(subset=['Name:String'])\n",
    "roleVdf['~id'] = np.arange(len(roleVdf))\n",
    "roleVdf['~id'] = roleVdf['~id'].apply(lambda x: f\"role{x}\")\n",
    "roleVdf.to_csv(os.path.join(output_folder, 'vertex_role.csv'), index=False)\n",
    "role_map = pd.Series(roleVdf['~id'].values,index=roleVdf['Name:String']).to_dict()\n",
    "\n",
    "# Create the EducationField dataframe\n",
    "fieldVdf = pd.DataFrame(columns=['~id', \n",
    "                               'Name:String',                                \n",
    "                               '~label'])\n",
    "fieldVdf['Name:String'] = df['EducationField']\n",
    "\n",
    "fieldVdf['~label'] = 'EducationField'\n",
    "fieldVdf = fieldVdf.drop_duplicates(subset=['Name:String'])\n",
    "fieldVdf['~id'] = np.arange(len(fieldVdf))\n",
    "fieldVdf['~id'] = fieldVdf['~id'].apply(lambda x: f\"field{x}\")\n",
    "fieldVdf.to_csv(os.path.join(output_folder, 'vertex_field.csv'), index=False)\n",
    "field_map = pd.Series(fieldVdf['~id'].values,index=fieldVdf['Name:String']).to_dict()\n",
    "\n",
    "# Construct our edges\n",
    "edge_emp_dept = pd.DataFrame(columns=['~id', '~from', '~to', '~label'])\n",
    "edge_emp_role = pd.DataFrame(columns=['~id', '~from', '~to', '~label'])\n",
    "edge_emp_field = pd.DataFrame(columns=['~id', '~from', '~to', '~label'])\n",
    "edge_role_dept = pd.DataFrame(columns=['~id', '~from', '~to', '~label'])\n",
    "edge_role_field = pd.DataFrame(columns=['~id', '~from', '~to', '~label'])\n",
    "edge_cnt = 1\n",
    "role_dept_list = []\n",
    "role_field_list = []\n",
    "\n",
    "edge_emp_dept_rows_list = [edge_emp_dept]\n",
    "edge_emp_role_rows_list = [edge_emp_role]\n",
    "edge_emp_field_rows_list = [edge_emp_field]\n",
    "edge_role_dept_rows_list = [edge_role_dept]\n",
    "edge_role_field_rows_list = [edge_role_field]\n",
    "\n",
    "for index, row in df.iterrows():\n",
    "    emp = row['EmployeeNumber']\n",
    "    emp_id = emp_map[emp]\n",
    "    role = row['JobRole']\n",
    "    role_id = role_map[role]\n",
    "    field = row['EducationField']\n",
    "    field_id = field_map[field]\n",
    "    dept = row['Department']\n",
    "    dept_id = dept_map[dept]\n",
    "\n",
    "    edge_emp_dept_row_df = pd.DataFrame.from_dict({'~id': uuid.uuid4(),\n",
    "                                                   '~from': emp_id,\n",
    "                                                   '~to': dept_id,\n",
    "                                                   '~label': 'works_in'},\n",
    "                                                  orient='index').T\n",
    "    edge_emp_dept_rows_list.append(edge_emp_dept_row_df)\n",
    "    edge_emp_role_row_df = pd.DataFrame.from_dict({'~id': uuid.uuid4(),\n",
    "                                                   '~from': emp_id,\n",
    "                                                   '~to': role_id,\n",
    "                                                   '~label': 'works_as'},\n",
    "                                                  orient='index').T\n",
    "    edge_emp_role_rows_list.append(edge_emp_role_row_df)\n",
    "    edge_emp_field_row_df = pd.DataFrame.from_dict({'~id': uuid.uuid4(),\n",
    "                                                    '~from': emp_id,\n",
    "                                                    '~to': field_id,\n",
    "                                                    '~label': 'has_education_level'},\n",
    "                                                   orient='index').T\n",
    "    edge_emp_field_rows_list.append(edge_emp_field_row_df)\n",
    "    \n",
    "    role_dept = f\"{role_id}-{dept_id}\"\n",
    "    role_field = f\"{role_id}-{field_id}\"\n",
    "    if role_dept not in role_dept_list:\n",
    "        edge_role_dept_row_df = pd.DataFrame.from_dict({'~id': uuid.uuid4(),\n",
    "                                                        '~from': role_id,\n",
    "                                                        '~to': dept_id,\n",
    "                                                        '~label': 'part_of'},\n",
    "                                                       orient='index').T\n",
    "        edge_role_dept_rows_list.append(edge_role_dept_row_df)\n",
    "        #edge_role_dept = pd.concat([edge_role_dept, edge_role_dept_row_df], ignore_index=True)\n",
    "        role_dept_list.append(role_dept)\n",
    "    if role_field not in role_field_list:\n",
    "        edge_role_field_row_df = pd.DataFrame.from_dict({'~id': uuid.uuid4(), '~from': role_id,\n",
    "                                                         '~to': field_id,\n",
    "                                                         '~label': 'requires'},\n",
    "                                                        orient='index').T\n",
    "        edge_role_field_rows_list.append(edge_role_field_row_df)\n",
    "        role_field_list.append(role_field)\n",
    "    edge_cnt = edge_cnt + 1\n",
    "\n",
    "edge_emp_dept = pd.concat(edge_emp_dept_rows_list, ignore_index=True)\n",
    "edge_emp_role = pd.concat(edge_emp_role_rows_list, ignore_index=True)\n",
    "edge_emp_field = pd.concat(edge_emp_field_rows_list, ignore_index=True)\n",
    "edge_role_dept = pd.concat(edge_role_dept_rows_list, ignore_index=True)\n",
    "edge_role_field = pd.concat(edge_role_field_rows_list, ignore_index=True)\n",
    "\n",
    "edge_df = pd.concat([edge_emp_dept, edge_emp_role, edge_emp_field, edge_role_dept,  edge_role_field])\n",
    "edge_df.to_csv(os.path.join(output_folder, 'edge.csv'), index=False)\n",
    "\n",
    "# Upload the CSV files to the S3 bucket\n",
    "s3 = boto3.client('s3')\n",
    "path = urlparse(s3_bucket_uri, allow_fragments=False)\n",
    "bucket = path.netloc\n",
    "file_path = path.path.lstrip('/').rstrip('/')\n",
    "for f in ['vertex_dept.csv', 'vertex_emp.csv', 'vertex_field.csv', 'vertex_role.csv', 'edge.csv']:\n",
    "    s3.upload_file(os.path.join(output_folder, f), bucket, os.path.join(file_path, f))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "727cf589",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load -s {s3_bucket_uri} -f csv -p OVERSUBSCRIBE --run"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c8fc4e4",
   "metadata": {},
   "source": [
    "## Inspecting our HR Data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1f79e58f",
   "metadata": {},
   "source": [
    "First, let's see how many unique vertices and edges we have."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "772469ce",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.V().groupCount().by(label).unfold()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54685984",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.E().groupCount().by(label).unfold()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b946e19e",
   "metadata": {},
   "source": [
    "Next, let's visualize the entire employee list and the job role.  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd025190",
   "metadata": {},
   "outputs": [],
   "source": [
    "role_emp_node_labels = '{\"JobRole\":\"Name\",\"Department\":\"Name\",\"EducationField\":\"Name\"}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c02fca33",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin -d $role_emp_node_labels\n",
    "g.V().hasLabel('Employee').outE('works_as').inV().path().by(elementMap())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0523ab36",
   "metadata": {},
   "source": [
    "To make the graph a little more intuitive, let's ask a more specific question: \n",
    "\n",
    "**Which job roles tend to have the most attrition?**\n",
    "\n",
    "We could easily change this to look by department or by education."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "513f1c9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin -d $role_emp_node_labels\n",
    "g.V().hasLabel('Employee').has('Attrition', 'Yes').outE('works_as').inV().path().by(elementMap())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ac8888d",
   "metadata": {},
   "source": [
    "Now let's look at the relationship between departments and job roles."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39e89991",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin -d $role_emp_node_labels  -l 20\n",
    "g.V().hasLabel('JobRole').outE('part_of').inV().path().by(elementMap())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "51662ad5",
   "metadata": {},
   "source": [
    "Our last visualization shows the relationship between job roles and education."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45085c06",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin -d $role_emp_node_labels  -l 20\n",
    "g.V().hasLabel('JobRole').outE('requires').inV().path().by(elementMap())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "24976663",
   "metadata": {},
   "source": [
    "## Using Neptune ML\n",
    "\n",
    "As a reminder, we will try to predict the following:\n",
    "\n",
    "* Attrition - since this is a categorical (as opposed to numerical) property of the `Employee` vertex, we will use a [Node Classification](https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning.html#machine-learning-capabilities) task.\n",
    "* Career Progression - Predicting career progression in our model is a matter of predicting a relationship between an `Employee` and a `JobRole` so we will use a [Link Prediction](https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning.html#machine-learning-capabilities) task."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6310f7ed",
   "metadata": {},
   "source": [
    "### Predicting attrition using Node Classification\n",
    "\n",
    "Node classification is a task supported by Neptune ML that supports predicting the categorical (i.e. string) value from a set of options included in the training data.  In our example, we will use the `Attrition` field as the 'Yes/No' categorical field on which we perform our prediction tasks.\n",
    "\n",
    "Before we can go about building our model, we'll start by dropping the field from the first 50 employees, in order to have some values to predict on."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5f78857",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "\n",
    "g.V().hasLabel('Employee').limit(50).properties('Attrition').drop()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8295567",
   "metadata": {},
   "source": [
    "Now that we have prepared our dataset, the first step in the process of building our Attrition Prediction model is to export the data and configuration.  \n",
    "\n",
    "**Note:** The details of how this is configured and the options available are covered in the [Neptune ML documentation](https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-data-export.html#machine-learning-params) as well as the [Neptune-ML-01-Introduction-to-Node-Classification-Gremlin notebook](https://github.com/aws/graph-notebook/blob/main/src/graph_notebook/notebooks/04-Machine-Learning/Neptune-ML-01-Introduction-to-Node-Classification-Gremlin.ipynb), so we will not cover the detail here.\n",
    "\n",
    "For our `Attrition` prediction model, we have specified our targets as the `Attrition` property of the `Employee` vertices as shown here:\n",
    "```\n",
    "\"targets\": [\n",
    "            {\n",
    "              \"node\": \"Employee\",\n",
    "              \"property\": \"Attrition\"\n",
    "            }\n",
    "```\n",
    "\n",
    "In addition, we have specified several details about features within our data set in order to best represent the data in the model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "daaa5659",
   "metadata": {},
   "outputs": [],
   "source": [
    "s3_bucket_uri = f's3://{bucket}/empml'\n",
    "export_params={ \n",
    "\"command\": \"export-pg\", \n",
    "\"params\": { \"endpoint\": neptune_ml.get_host(),\n",
    "            \"profile\": \"neptune_ml\",\n",
    "           \"useIamAuth\": neptune_ml.get_iam(),\n",
    "            \"cloneCluster\": False\n",
    "            }, \n",
    "\"outputS3Path\": f'{s3_bucket_uri}/neptune-export',\n",
    "\"additionalParams\": {\n",
    "        \"neptune_ml\": {\n",
    "            \"targets\": [\n",
    "            {\n",
    "              \"node\": \"Employee\",\n",
    "              \"property\": \"Attrition\",\n",
    "              \"type\": \"classification\"\n",
    "            }\n",
    "          ],\n",
    "         \"features\": [\n",
    "            {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"Age\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [17, 65],\n",
    "                \"num_buckets\": 10\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"BusinessTravel\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"DailyRate\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [100, 2000],\n",
    "                \"num_buckets\": 10\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"NumCompaniesWorked\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [0, 15],\n",
    "                \"num_buckets\": 16\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"Education\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"JobInvolvement\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"JobLevel\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"JobSatisfaction\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"PercentSalaryHike\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [5, 40],\n",
    "                \"num_buckets\": 10\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"PerformanceRating\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"WorkLifeBalance\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"YearsAtCompany\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [0, 45],\n",
    "                \"num_buckets\": 10\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"YearsInCurrentRole\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [0, 20],\n",
    "                \"num_buckets\": 10\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"YearsSinceLastPromotion\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [0, 20],\n",
    "                \"num_buckets\": 20\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"YearsWithCurrManager\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [0, 20],\n",
    "                \"num_buckets\": 20\n",
    "            }\n",
    "         ]\n",
    "        }\n",
    "      },\n",
    "\"jobSize\": \"large\"}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "029b787f",
   "metadata": {},
   "source": [
    "With our configuration ready, we can now export our data and configuration, which will take several minutes, using the command below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d609ee8d",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%neptune_ml export start --export-url {neptune_ml.get_export_service_host()} --export-iam --wait --store-to export_results\n",
    "${export_params}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "097e4da1",
   "metadata": {},
   "source": [
    "The next step in building our Attrition Prediction model is to run the [data processing](https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-on-graphs-processing.html) job, which takes our exported data and transforms it into the form used by the [Deep Graph Library](https://www.dgl.ai/).  Run the next two cells to create the training configuration and then to run the training job, which takes 5-10 minutes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8afa9b4b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# The training_job_name can be set to a unique value below, otherwise one will be auto-generated\n",
    "training_job_name=neptune_ml.get_training_job_name('node-classification')\n",
    "\n",
    "processing_params = f\"\"\"\n",
    "--config-file-name training-data-configuration.json\n",
    "--job-id {training_job_name} \n",
    "--s3-input-uri {export_results['outputS3Uri']} \n",
    "--s3-processed-uri {str(s3_bucket_uri)}/preloading \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e8bbd720",
   "metadata": {},
   "outputs": [],
   "source": [
    "%neptune_ml dataprocessing start --wait --store-to processing_results {processing_params}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62e140e8",
   "metadata": {},
   "source": [
    "Once the data processing complete, the next step is to run the [model training](https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-on-graphs-model-training.html) which will create the DGL model for our Attrition Prediction task. Run the next two cells to create the training configuration and then to run the training job, which takes 10-15 minutes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "213363a6",
   "metadata": {},
   "outputs": [],
   "source": [
    "training_params=f\"\"\"\n",
    "--job-id {training_job_name} \n",
    "--data-processing-id {training_job_name} \n",
    "--instance-type ml.m5.2xlarge\n",
    "--s3-output-uri {str(s3_bucket_uri)}/training \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "02586fb0",
   "metadata": {},
   "outputs": [],
   "source": [
    "%neptune_ml training start --wait --store-to training_results {training_params}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9138a991",
   "metadata": {},
   "source": [
    "Now that we have trained our model, the final step is to create a Sagemaker-hosted [inference endpoint](https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-on-graphs-inference-endpoint.html) that will allow us to query our prediction model. This step should take 5-10 minutes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f05c4544",
   "metadata": {},
   "outputs": [],
   "source": [
    "endpoint_params=f\"\"\"\n",
    "--id {training_job_name}\n",
    "--model-training-job-id {training_job_name}\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7a4779b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "%neptune_ml endpoint create --wait --store-to endpoint_results {endpoint_params}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb0ceb26",
   "metadata": {},
   "outputs": [],
   "source": [
    "endpoint = endpoint_results['endpoint']['name']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91bd6b83",
   "metadata": {},
   "source": [
    "### Testing our Attrition prediction task\n",
    "\n",
    "Now that we have built our model and have it hosted, let's test it out and see how we can use this to predict potential employee attrition.\n",
    "\n",
    "#### Which employees are likely to leave?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6107d4ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin  -d $role_emp_node_labels\n",
    "g.with(\"Neptune#ml.endpoint\", \"${endpoint}\").\n",
    "  V().\n",
    "  hasLabel('Employee').\n",
    "  hasNot('Attrition').\n",
    "  project('EmployeeNumber', 'Attrition').\n",
    "    by('EmployeeNumber').\n",
    "    by(\n",
    "      properties(\"Attrition\").with(\"Neptune#ml.classification\").value()).\n",
    "  group().by('Attrition').by('EmployeeNumber').\n",
    "  unfold()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05c83b70",
   "metadata": {},
   "source": [
    "#### Of the employees without a value, how many are going to leave versus stay?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "385cf507",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin  -d $role_emp_node_labels\n",
    "g.with(\"Neptune#ml.endpoint\", \"${endpoint}\").\n",
    "  V().\n",
    "  hasLabel('Employee').\n",
    "  hasNot('Attrition').\n",
    "  project('EmployeeNumber', 'Attrition').\n",
    "    by('EmployeeNumber').\n",
    "    by(\n",
    "      properties(\"Attrition\").with(\"Neptune#ml.classification\").value()).\n",
    "  groupCount().by('Attrition').\n",
    "  unfold()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa524674",
   "metadata": {},
   "source": [
    "#### What JobRoles have the most employees predicted to leave?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2b122f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin  -d $role_emp_node_labels\n",
    "g.with(\"Neptune#ml.endpoint\", \"${endpoint}\").\n",
    "  V().\n",
    "  hasLabel('Employee').\n",
    "  hasNot('Attrition').as('e').\n",
    "  properties(\"Attrition\").with(\"Neptune#ml.classification\").\n",
    "  value().\n",
    "  is('Yes').\n",
    "  select('e').\n",
    "  out('works_as').\n",
    "  values('Name').\n",
    "  groupCount().\n",
    "  unfold().\n",
    "  order().by(values, desc)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "085381c0",
   "metadata": {},
   "source": [
    "## Predicting career progression with link prediction\n",
    "\n",
    "Link prediction is a task supported by Neptune ML that supports predicting edges (or relationships) between two vertices in the graph.  In our example, we will be predicting `works_as` relationships between an `Employee` and a `JobRole`.\n",
    "\n",
    "Before we can go about building our model, we'll start by dropping the `works_as` edge from 50 employees, in order to have some values to predict on."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aa3c748d",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.V().hasLabel('Employee').limit(50).outE('works_as').drop()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c4da2be",
   "metadata": {},
   "source": [
    "Now that we have prepared our dataset, we are going to follow the same steps we used in our Attrition Prediction model is to export the data and configuration, prepare the data, train the model, and create the inference endpoint.  We are not going to cover each of these steps in detail so run the next six cells below in order which will take about 30-45 minutes total."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a1f73b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "s3_bucket_uri = f's3://{bucket}/empmllink'\n",
    "export_params_link ={ \n",
    "\"command\": \"export-pg\", \n",
    "\"params\": { \"endpoint\": neptune_ml.get_host(),\n",
    "            \"profile\": \"neptune_ml\",\n",
    "           \"useIamAuth\": neptune_ml.get_iam(),\n",
    "            \"cloneCluster\": False\n",
    "            }, \n",
    "\"outputS3Path\": f'{s3_bucket_uri}/neptune-export-link',\n",
    "\"additionalParams\": {\n",
    "        \"neptune_ml\": {\n",
    "         \"features\": [\n",
    "             {\n",
    "                \"node\": \"JobRole\",\n",
    "                \"property\": \"Name\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "            {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"Age\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [17, 65],\n",
    "                \"num_buckets\": 10\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"BusinessTravel\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"DailyRate\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [100, 2000],\n",
    "                \"num_buckets\": 10\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"NumCompaniesWorked\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [0, 15],\n",
    "                \"num_buckets\": 3\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"Education\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"JobInvolvement\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"JobLevel\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"JobSatisfaction\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"PercentSalaryHike\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [5, 40],\n",
    "                \"num_buckets\": 3\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"employee\",\n",
    "                \"property\": \"PerformanceRating\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"WorkLifeBalance\",\n",
    "                \"type\": \"category\"\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"YearsAtCompany\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [0, 45],\n",
    "                \"num_buckets\": 3\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"YearsInCurrentRole\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [0, 20],\n",
    "                \"num_buckets\": 3\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"YearsSinceLastPromotion\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [0, 20],\n",
    "                \"num_buckets\": 3\n",
    "            },\n",
    "             {\n",
    "                \"node\": \"Employee\",\n",
    "                \"property\": \"YearsWithCurrManager\",\n",
    "                \"type\": \"bucket_numerical\",\n",
    "                \"range\" : [0, 20],\n",
    "                \"num_buckets\": 3\n",
    "            }\n",
    "         ]\n",
    "        }\n",
    "      },\n",
    "\"jobSize\": \"large\"}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87cbbc58",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%neptune_ml export start --export-url {neptune_ml.get_export_service_host()} --export-iam --wait --store-to export_results\n",
    "${export_params_link}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f857ef12",
   "metadata": {},
   "outputs": [],
   "source": [
    "# The training_job_name can be set to a unique value below, otherwise one will be auto generated\n",
    "training_job_name_link=neptune_ml.get_training_job_name('link-prediction')\n",
    "\n",
    "processing_params_link = f\"\"\"\n",
    "--config-file-name training-data-configuration.json\n",
    "--job-id {training_job_name_link} \n",
    "--s3-input-uri {export_results['outputS3Uri']} \n",
    "--s3-processed-uri {str(s3_bucket_uri)}/preloading_link \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f79cc94",
   "metadata": {},
   "outputs": [],
   "source": [
    "%neptune_ml dataprocessing start --wait --store-to processing_results {processing_params_link}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ebc5319b",
   "metadata": {},
   "outputs": [],
   "source": [
    "training_params_link=f\"\"\"\n",
    "--job-id {training_job_name_link} \n",
    "--data-processing-id {training_job_name_link} \n",
    "--instance-type ml.m5.2xlarge\n",
    "--s3-output-uri {str(s3_bucket_uri)}/training_link \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "70d47eaf",
   "metadata": {},
   "outputs": [],
   "source": [
    "%neptune_ml training start --wait --store-to training_results {training_params_link}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "55c587e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "endpoint_params_link=f\"\"\"\n",
    "--id {training_job_name_link} \n",
    "--model-training-job-id {training_job_name_link}\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c35f339e",
   "metadata": {},
   "outputs": [],
   "source": [
    "%neptune_ml endpoint create --wait --store-to endpoint_results {endpoint_params_link}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4213424b",
   "metadata": {},
   "outputs": [],
   "source": [
    "lp_endpoint= endpoint_results['endpoint']['name']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "915e6616",
   "metadata": {},
   "source": [
    "### Testing our Career Progression prediction task\n",
    "\n",
    "Now that we have built our model and have it hosted, let's  test it out and see how we can use this to predict potential jobs for an employee.\n",
    "\n",
    "#### What is the most likely job for an employee?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bababf71",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin  -d $role_emp_node_labels\n",
    "\n",
    "g.with(\"Neptune#ml.endpoint\",\"${lp_endpoint}\").\n",
    "    V().hasLabel('Employee').where(outE('works_as').count().is(0)).\n",
    "    out('works_as').\n",
    "    with(\"Neptune#ml.prediction\").hasLabel('JobRole').path().by(elementMap())\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b4091806",
   "metadata": {},
   "source": [
    "#### Which job role has the most predicted employees?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8bc09bd7",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin  -d $role_emp_node_labels\n",
    "\n",
    "g.with(\"Neptune#ml.endpoint\",\"${lp_endpoint}\").\n",
    "    V().hasLabel('Employee').out('works_as').\n",
    "    with(\"Neptune#ml.prediction\").hasLabel('JobRole').groupCount().by('Name').unfold()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f1f220c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%gremlin  -d $role_emp_node_labels\n",
    "\n",
    "g.with(\"Neptune#ml.endpoint\",\"${lp_endpoint}\").with(\"Neptune#ml.limit\",5).\n",
    "    V().hasLabel('Employee').where(outE('works_as').count().is(0)).\n",
    "    out('works_as').\n",
    "    with(\"Neptune#ml.prediction\").hasLabel('JobRole').path().by(elementMap())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4fb58911",
   "metadata": {},
   "source": [
    "# Cleaning up \n",
    "Now that you have completed this walkthrough, you have created a Sagemaker endpoint which is currently running and will incur the standard charges.  If you are done using Neptune ML for this exercise, and would like to avoid  future costs, run the cell below to delete the inference endpoint."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81cc82ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "neptune_ml.delete_endpoint(training_job_name)\n",
    "neptune_ml.delete_endpoint(training_job_name_link)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
